package com.liyiqing.secondhandmall.productservice.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.liyiqing.secondhandmall.productservice.entity.ProductGroupEntity;
import com.liyiqing.secondhandmall.productservice.service.ProductGroupService;
import com.liyiqing.commonservice.utils.PageUtils;
import com.liyiqing.commonservice.utils.R;

import javax.annotation.Resource;


/**
 * 二级分类
 *
 * @author LiYiQing
 * @email 1570865668@qq.com
 * @date 2022-02-18 23:36:20
 */
@RestController
@RequestMapping("productService/productGroup")
public class ProductGroupController {
    @Autowired
    private ProductGroupService productGroupService;

    //redis工具
    @Resource
    private StringRedisTemplate stringRedisTemplate;



    /**
     * 根据一级目录的id，查找二级目录
     */
    @RequestMapping("/selectProductGroup/{catalogId}")
    public R selectProductGroup(@PathVariable("catalogId") Long catalogId){
        return productGroupService.selectProductGroupByCatalogId(catalogId);
    }




    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = productGroupService.queryPage(params);

        return R.ok().put("page", page);
    }



    /**
     * 信息
     */
    @RequestMapping("/info/{groupId}")
    public R info(@PathVariable("groupId") Long groupId){
		ProductGroupEntity productGroup = productGroupService.getById(groupId);

        return R.ok().put("productGroup", productGroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ProductGroupEntity productGroup){
		productGroupService.save(productGroup);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ProductGroupEntity productGroup){
		productGroupService.updateById(productGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] groupIds){
		productGroupService.removeByIds(Arrays.asList(groupIds));

        return R.ok();
    }

}
